<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScorll from "better-scroll";
import ObserveDom from "@better-scroll/observe-dom"
BScorll.use(ObserveDom)
export default {
  name: "Scroll",
  data(){
    return{
      bScroll:null
    }
  },
  props:{
    probeType:{
      type:Number,
      default:0
    }
    ,
    pullUpLoad:{
      type:Boolean,
      default: false
    }
  },
  mounted() {
    //1.创建BScroll对象
    this.bScroll=new BScorll(this.$refs.wrapper,{
      probeType:this.probeType,
      pullUpLoad: this.pullUpLoad,
      observeDOM:true,
      click:true
    })
  //  2.监听滚动的区域
    this.bScroll.on('scroll',position=>{
      this.$emit('scroll',position)
    })
    //监听上拉加载更多
    this.bScroll.on('pullingUp',()=>{
      this.$emit('pullingUp')
    })
  },
  methods:{
    bScrollTO(x,y,time=700){
      this.bScroll.scrollTo(x,y,time)
    },
    finishedPullingUp(){
      this.bScroll&&this.bScroll.finishPullUp()
    },
    refresh(){
      this.bScroll.refresh()
    },
    getY(){
      return this.bScroll.y?this.bScroll.y:0
    }
  }
}
</script>

<style scoped>

</style>
